package com.it.myh;

/**
 * 静态代理：代理类对象和被代理对象在编译期间，就被确定下来了
 */

//接口
interface ClothFactory{
    void produceCloth();
}

//代理类
class ProxyClothFactory implements ClothFactory{

    private ClothFactory factory;   //被代理类对象

    public ProxyClothFactory(ClothFactory factory){ //通过被代理类对象，来实例化代理类对象
        this.factory = factory;
    }

    @Override
    public void produceCloth() {
        System.out.println("代理类工厂做了一些准备！");
        factory.produceCloth();
        System.out.println("代理类工厂做了一些后续工作！");
    }
}

//被代理类
class NikeClothFactory implements ClothFactory{

    @Override
    public void produceCloth() {
        System.out.println("Nike生产一批运动服！");
    }
}


public class Od_0221_01 {

    public static void main(String[] args) {

        //创建被代理类对象
        ClothFactory nike = new NikeClothFactory();

        //创建代理类对象
        ClothFactory proxyClothFactory = new ProxyClothFactory(nike);

        proxyClothFactory.produceCloth();
    }
}
